package org.xt.service;

import java.io.File;

import org.xt.constants.Const;

import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;

public class BdbService {
	private static Environment env;
	/**
	 * 应用初始化时候调用
	 */
	public void setEnv(){
		EnvironmentConfig config = new EnvironmentConfig();
		config.setTransactional(false);
		config.setAllowCreate(true);
		try {
			env = new Environment(new File(Const.BDB_PATH), config);
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void close(){
		try{
			env.sync();
			env.close();
		}catch(Exception e){
			e.printStackTrace();
			env = null;
		}
	}
}
